package org.example.position.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

@Component
public class DBHelper {

    @Value("${spring.dbHelper.url}")
    private String url;
    @Value("${spring.dbHelper.driverClass}")
    private String driverClass;
    @Value("${spring.dbHelper.user}")
    private String user;
    @Value("${spring.dbHelper.password}")
    private String password;

    public Connection getConnection() {
        try {
            Class.forName(driverClass);
            Connection connection = DriverManager.getConnection(url, user, password);
            return connection;
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

}
